package com.ffsky.logger.demo;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.ffsky.logger.L;
import com.ffsky.logger.demo.databinding.ActivityMainBinding;
import com.gitee.hljdrl.logger.AndroidLogout;
import com.gitee.hljdrl.tinylog.TinyLogFileLogout;

import java.io.File;

public class MainActivity extends AppCompatActivity {

    private String TAG = "MainActivity";

    ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());

        File logger_dir = new File(getExternalCacheDir(), "logger");
        if (!logger_dir.exists()) {
            logger_dir.mkdirs();
        }

        setContentView(binding.getRoot());
        binding.btnSetAndroidLogger.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                L.setLogOut(new AndroidLogout());
            }
        });

        binding.btnSetTinyLogger.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                L.setLogOut(new TinyLogFileLogout(logger_dir.toString()));
                binding.btnSetTinyFile.setText(L.getFile());
            }
        });

        binding.btnLogOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < 20; i++) {
                    L.i(TAG, "logger ", i);
                }
            }
        });

    }
}